import { applicableStageOptions, arr2option } from "@/utils";
import { cloneDeep } from "lodash-es";

const scaleOptions = arr2option([
  "国际",
  "国家",
  "城市",
  "区县",
  "镇街道",
  "社区",
]);
const typeOptions = arr2option(["通用", "商务区", "产业园区", "居住区"]);
const capitalOptions = arr2option(["社会项目", "绿色项目", "气候转型项目"]);
const temperatureOptions = arr2option([
  "寒温带",
  "中温带",
  "暖温带",
  "北亚热带",
  "中亚热带",
  "南亚热带",
  "边缘热带",
  "中热带",
  "赤道热带",
  "高原亚寒带",
  "高原亚热带",
  "高原温带",
]);
const humidityOptions = arr2option(["湿润", "半湿润", "半干旱", "干旱"]);
const heatOptions = arr2option([
  "严寒地区",
  "寒冷地区",
  "夏热冬冷地区",
  "夏热冬暖地区",
  "温和地区",
]);
const geographyOptions = arr2option(["高原", "山地", "平原", "丘陵", "盆地"]);
const biasOptions = arr2option([
  "可持续城市",
  "低碳城市/近零碳城市",
  "生态城市",
  "安全城市",
  "健康城市",
  "海绵城市",
  "无废城市",
  "智慧城市",
  "韧性城市",
  "城市更新",
  "城市监测",
  "科技城市",
]);
/**
 * @description: 新建指标体系-基本信息
 */
export const createBasicInfoForm = [
  {
    type: "input",
    label: "名称",
    key: "name",
    props: {
      placeholder: "请输入指标库名称",
    },
  },
  {
    type: "input",
    label: "版本号",
    key: "version",
  },
  {
    type: "editor",
    label: "介绍",
    key: "intro",
    props: {
      editorConfig: { placeholder: "请输入体系介绍，版本内容更新说明" },
      toolbarConfig: {},
    },
  },
];
/**
 * @description: 新建指标体系-筛选条件
 */
export const createFilterCondtitionForm: FormStaticItem[] = [
  {
    label: "偏重体系",
    key: "bias",
    type: "select",
    required: false,
    props: {
      options: biasOptions,
    },
  },
  {
    label: "适用规模",
    key: "scale",
    type: "select",
    required: false,
    props: {
      options: scaleOptions,
    },
  },
  {
    label: "适用类型",
    key: "type",
    type: "select",
    required: false,
    props: {
      options: typeOptions,
    },
  },
  {
    label: "适用阶段",
    key: "stage",
    type: "select",
    required: false,
    props: {
      options: applicableStageOptions.concat({ label: "其他", value: "其他" }),
    },
  },
  {
    label: "资产组合类型",
    key: "capital",
    type: "select",
    required: false,
    props: {
      options: capitalOptions,
    },
  },
];
/**
 * @description: 新建指标体系-智能推荐
 */
const recommendIndicatorsColumns: ColumnItem[] = [
  {
    title: "三级指标",
    dataIndex: `ind3Zh`,
    width: 200,
    resizable: true,
    ellipsis: true,
    isCustom: true,
    fixed: "left",
  },
  {
    title: "所属二级指标",
    dataIndex: `ind2Zh`,
    width: 200,
    resizable: true,
    ellipsis: true,
  },
  {
    title: "所属一级指标",
    dataIndex: `ind1Zh`,
    width: 200,
    resizable: true,
    ellipsis: true,
  },
  {
    title: "指标模块类型",
    dataIndex: `modal`,
    width: 200,
    resizable: true,
    ellipsis: true,
  },
  {
    title: "指标考核级别",
    dataIndex: `assessmentLevel`,
    width: 200,
    resizable: true,
    ellipsis: true,
  },
  {
    title: "指标方向",
    dataIndex: `direction`,
    width: 200,
    resizable: true,
    ellipsis: true,
  },
  {
    title: "指标评估方式",
    dataIndex: `evaluationMethod`,
    width: 200,
    resizable: true,
    ellipsis: true,
  },
  ...createFilterCondtitionForm.map((item) => ({
    title: item.label,
    dataIndex: item.key,
    width: 200,
    resizable: true,
    isCustom: true,
  })),
];
export const getRecommandIndicatorsColumns = () =>
  cloneDeep(recommendIndicatorsColumns);
export const basicInfoForm = [
  {
    type: "input",
    label: "名称",
    key: "name",
    props: {
      placeholder: "请输入指标库名称",
    },
  },
  ...createFilterCondtitionForm,
  {
    label: "温度带",
    key: "temperature",
    type: "select",
    props: {
      options: temperatureOptions,
    },
  },
  {
    label: "干湿区",
    key: "humidity",
    type: "select",
    props: {
      options: humidityOptions,
    },
  },
  {
    label: "建筑热工分区",
    key: "heat",
    type: "select",
    props: {
      options: heatOptions,
    },
  },
  {
    label: "地理特征",
    key: "geography",
    type: "select",
    props: {
      options: geographyOptions,
    },
  },
  {
    type: "input",
    label: "版本号",
    key: "version",
  },
  {
    type: "editor",
    label: "介绍",
    key: "intro",
    props: {
      editorConfig: { placeholder: "请输入体系介绍，版本内容更新说明" },
      toolbarConfig: {},
    },
  },
  {
    key: "fileId",
    type: "upload",
    label: "指标文件",
    props: {
      // templateName: "指导导则模版",
      buttonText: "上传",
      maxCount: 1,
    },
  },
];
const num = ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"];
export const getIndicatorColumns = (level: number) => {
  const res: ColumnItem[] = [];
  const arr = new Array(level).fill(0);
  arr.forEach((item, index) => {
    res.push({
      title: index === 0 ? "指标模块类型" : `${num[index - 1]}级指标`,
      children: [
        {
          title: "名称",
          dataIndex: `level${index + 1}Name`,
          width: 200,
          resizable: true,
          ellipsis: true,
          isCustom: true,
          customCell: (record) => {
            return { rowSpan: record[`level${index + 1}Span`] };
          },
        },
        ...(index === arr.length - 1
          ? [
              {
                title: "分值",
                dataIndex: "score",
                width: 60,
                resizable: true,
                ellipsis: true,
                align: "right",
              },
            ]
          : []),
        {
          title: "相对权重",
          dataIndex: `level${index + 1}Weights`,
          width: 90,
          resizable: true,
          ellipsis: true,
          isCustom: true,
          customRender({ text }) {
            return ![undefined, "", null].includes(text) ? text + "%" : "-";
          },
          customCell: (record) => {
            return { rowSpan: record[`level${index + 1}Span`] };
          },
        },
        ...(index === arr.length - 1
          ? [
              {
                title: "权重分值",
                dataIndex: "weightsScore",
                width: 90,
                resizable: true,
                ellipsis: true,
                align: "right",
              },
            ]
          : []),
      ],
    });
  });
  return res;
};
